

from rest_framework import serializers
from django.contrib.auth.models import Group



class GroupModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = Group
        fields = [
            'id',
            'name',

            # permissions = [76, 18]
            'permissions'
        ]


    # def create(self, validated_data):
    #
    #     # permissions = [76, 18]
    #     # 该字段你代表中间表数据新建
    #     permissions = validated_data.pop('permissions')
    #
    #     instance = Group.objects.create(**validated_data) # create(name='xxxxxx')
    #
    #     # permissions属性类型是ManyToManyField；在被赋值为一个列表的时候，会自动构建中间表数据
    #     # instance.permissions = permissions
    #     instance.permissions.set(permissions)
    #
    #     instance.save()
    #
    #     return instance











